package cn.genmer.test.security.controller;

import cn.genmer.test.security.aop.dynamicProxyImpl.CGLIBDynamicObject;
import cn.genmer.test.security.aop.dynamicProxyImpl.JDKDynamicObject;
import cn.genmer.test.security.model.American;
import cn.genmer.test.security.model.Chinese;
import cn.genmer.test.security.model.Person;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value="/aop")
public class AopImplementController {
    private Logger logger = LoggerFactory.getLogger(AopImplementController.class);

    
    @ResponseBody
    @RequestMapping(value="/talk")
    public String talk() {
        JDKDynamicObject dsc1 = new JDKDynamicObject();
        Person person1 = (Person) dsc1.bind(new Chinese());
        person1.say("中国人说汉语");
        logger.info("JDK动态代理生产代理对象执行 ==> talk method : JDKDynamicObject {}", person1.getClass());

        //自定义CGLIB动态代理
        CGLIBDynamicObject dsm = new CGLIBDynamicObject();
        American american1 = (American) dsm.bind(new American());
        american1.say("American say english");
        logger.info("CGLIB动态代理生产代理对象执行 ==> talk method : CGLIBDynamicObject {}", american1.getClass());
        return "success";
    }

}